package handler

import (
	"github.com/gin-gonic/gin"
	"github.com/spf13/cast"
	"honghu_be/common"
	"honghu_be/dal"
	"honghu_be/model"
)

func DeleteAd(c *gin.Context) {
	req := &model.DeleteAdRequest{}
	if err := c.ShouldBindUri(req); err != nil {
		c.JSON(400, err.Error())
		return
	}
	resp, err := deleteAd(c, req.AdId)
	if err != nil {
		common.WriteError(c, err)
		return
	}
	c.JSON(200, resp)
}

func deleteAd(c *gin.Context, adId string) (*model.DeleteAdResponse, error) {
	err := dal.DeleteAd(c, cast.ToInt(adId))
	if err != nil {
		return nil, err
	}
	return &model.DeleteAdResponse{
		Meta: common.MetaOk,
	}, nil
}
